﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using RungSoft.RungEBookMaker.Controls.Panels;

namespace RungSoft.RungEBookMaker
{
    public partial class MainForm : Form
    {
        WriteInfo mWriteInfo;

        public MainForm()
        {
            InitializeComponent();
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            mWriteInfo = WriteInfoListBox;

            tpDownloader.Controls.Add(new pnDownloader());
            tpEBookMaker.Controls.Add(new pnEBookMaker(mWriteInfo));
            tcMain.SelectedIndex = 1;
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        // 显示消息
        private void WriteInfoListBox(string msg, InfoType type)
        {
            switch (type)
            {
                case InfoType.Success:
                    msg = "[就绪]" + msg;
                    break;
                case InfoType.Warning:
                    msg = "[警告]" + msg;
                    break;
                case InfoType.Errer:
                    msg = "[错误]" + msg;
                    break;
            }

            lbInfo.Items.Add(msg);
        }


        private void btnConfig_Click(object sender, EventArgs e)
        {
            Panel p = new Panel();
            p.BackColor = Color.Red;
            p.Dock = DockStyle.Fill;

            lbInfo.Items.Add(p);
        }

        // 绘制 lbInfo 数据项
        private void lbInfo_DrawItem(object sender, DrawItemEventArgs e)
        {
            Brush brush = null;
            string item = lbInfo.Items[e.Index].ToString();

            if (item.StartsWith("[就绪]"))
            {
                brush = Brushes.DarkSlateGray;
            }
            else if (item.StartsWith("[警告]"))
            {
                brush = Brushes.SaddleBrown;
            }
            else if (item.StartsWith("[错误]"))
            {
                brush = Brushes.Maroon;
            }
            //System.Drawing.Font bFont = new System.Drawing.Font(e.Font, FontStyle.Bold);

            e.DrawBackground();
            e.Graphics.DrawString(item, e.Font, brush, e.Bounds);
            e.DrawFocusRectangle();
        }
    }

    internal delegate void WriteInfo(string msg,InfoType type);

    internal enum InfoType
    {
        Success,
        Warning,
        Errer
    }
}
